<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 * @author   howe <howe1995@163.com>
 */
use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

return new class() extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('messages', function (Blueprint $table) {
            $table->id();
            $table->integer('from_user')->unsigned()->default(0)->comment('发送者');
            $table->integer('to_user')->unsigned()->default(0)->comment('接受收者');
            $table->text('content')->nullable()->comment('消息内容，如果为文件或图片就是url');
            $table->enum('type', ['text', 'image', 'video', 'audio', 'emoji', 'file', 'video_call', 'audio_call', 'red_packet'])->default('text')->comment('消息类型：text、file、image...');
            $table->tinyInteger('is_group')->unsigned()->default(0)->comment('是否群聊消息');
            $table->tinyInteger('is_undo')->unsigned()->default(0)->comment('是否撤回');
            $table->tinyInteger('is_tips')->unsigned()->default(0)->comment('是否提示信息');
            $table->string('at_users')->default('')->comment('的用户');
            $table->unsignedBigInteger('pid')->default(0)->comment('引用的消息ID');
            $table->unsignedBigInteger('file_id')->default(0)->comment('文件id');
            $table->enum('file_type', ['file', 'video', 'image', 'audio'])->nullable()->comment('文件类型');
            $table->unsignedBigInteger('file_size')->default(0)->comment('文件大小');
            $table->string('file_name')->default('')->comment('文件名称');
            $table->json('extends')->nullable()->comment('消息扩展内容');
            $table->tinyInteger('status')->unsigned()->default(1)->comment('状态');
            $table->timestamp('created_at')->useCurrent()->comment('发送时间');
            $table->timestamp('updated_at')->useCurrent()->comment('更新时间');
            $table->string('deleted_users')->default('')->comment('已删除成员');
            $table->index(['from_user', 'to_user'], 'idx_from_to', 'BTREE');
            $table->comment('消息表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('messages');
    }
};
